import '../../assets/styles/nav.css';
import React from 'react';
import { Layout} from 'antd';
import MyHeader from './components/MyHeader';
import MySider from './components/MySider';
import MyContent from './components/MyContent';
import {getUserInfo} from '../../apis/httpRequest.js';
 export default function NavPage() {
	 React.useEffect(()=>{
	     eventBus.emit("refreshRoutes")
	 },[]);
	 const count = React.useRef(0);
	 const [tokenIsTrue,setTokenIsTrue] = React.useState(false);//这个值代表token的真假，默认是假的
	 const token = localStorage.token;
	 if(!token){
		 //如果没有登录
		 window.location.hash = '#/login';
		 return null;
	 }else{
		 //登录了
		 if(count.current == 0){
			 count.current ++;
			 getUserInfo()
			 .then(res =>{
				 setTokenIsTrue(true);
			 }).catch(err =>{
				 console.log("err",err);
			 });
		 }
		 
		 if(!tokenIsTrue){
			 //如果假的 返回null
			
			return null;
		 }else{
			 //如果真的 渲染
			 return (
			   <Layout style={{height:'100vh'}}>
			     <MyHeader/>
			     <Layout>
			 	    <MySider/>
			       <Layout style={{padding: '0 24px 24px'}}>
			 		<MyContent/>
			       </Layout>
			     </Layout>
			   </Layout>
			 );
		 }
	 }
  
};